// pages/myProcess/myProcess.js

Page({

  /**
   * 页面的初始数据
   */
  data: {
    circleList: [
      {
        id: 0,
        top: 0,
        date: '',
        text: ''
      }, {
        id: 1,
        top: '',
        date: '',
        text: ''
      }, {
        id: 2,
        top: '',
        date: '',
        text: ''
      }, {
        id: 3,
        top: '',
        date: '',
        text: ''
      }, {
        id: 4,
        top: '',
        date: '',
        text: ''
      }
    ],
    lineHeight: 0,
    flag: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    // 获取域名
    const app = getApp();
    const baseUrl = app.globalData.baseUrl;
    wx.request({
      url: baseUrl + '/stuNotice/queryAllMSGByOpenId?openId=' + wx.getStorageSync('openId'),
      success: (res) => {
        const ProcessData = res.data.data.length;

        for (let i = 0; i < ProcessData; i++) {
          this.data.circleList[i].date = res.data.data[i].gmtCreate;
          this.data.circleList[i].text = res.data.data[i].noticeContent;
        }
        const circleAll = this.data.circleList;
        const circleList = circleAll.slice(0, parseInt(ProcessData));

        const flag = 1;
        this.setData({
          circleList,
          flag
        })
        const tempArr = [];
        let sumHeight = 0;
        wx.createSelectorQuery().selectAll('.infor').boundingClientRect(function (res) {
          for (let i = 0; i < ProcessData; i++) {
            tempArr[i] = res[i].height;
          }
        }).exec()
        let initHeight = 38;
        setTimeout(() => {
          let info = wx.getSystemInfoSync();
          if (/iPad/i.test(info.model)) {
            initHeight = 93;
          }
          for (let i = 1; i < ProcessData; i++) {
            sumHeight += tempArr[i];
            this.data.circleList[i].top = parseInt(this.data.circleList[i - 1].top) + tempArr[i - 1] + initHeight + 'px';
          }
          sumHeight = sumHeight + tempArr[0] + 30 * ProcessData;
          const lineHeight = sumHeight + 'px';
          this.setData({
            circleList,
            lineHeight
          })
        }, 500);

      },
    });

  },
  onPullDownRefresh: function () {
    this.onLoad();
    wx.stopPullDownRefresh();
  },
})
